package com.yugu.park.business.controller;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.github.pagehelper.PageInfo;
import com.yugu.enums.BusinessType;
import com.yugu.park.annotation.Log;
import com.yugu.park.business.entity.MemberInfo;
import com.yugu.park.business.service.MemberInfoService;
import com.yugu.park.dto.CardDto;
import com.yugu.park.dto.MemberInfoDto;
import com.yugu.util.ResponseUtil;
import com.yugu.util.SearchPage;
import com.yugu.util.SysQueryParam;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.Arrays;
import java.util.List;

/**
 * @author Noble-Six
 * @date 2024/4/25
 */
@RestController
@Api(tags = "会员信息")
@RequestMapping("/business/memberinfo")
public class MemberInfoController {
    @Resource
    private MemberInfoService memberInfoService;

    @ApiOperation(value = "新增修改会员信息")
    @PostMapping("/addOrUpdate")
    @Log(title ="新增修改会员信息" ,businessType = BusinessType.UPDATE)
    public ResponseUtil.Result<Boolean> addOrUpdate(@RequestBody MemberInfoDto infoDto){
        memberInfoService.addOrUpdate(infoDto);
        return ResponseUtil.addSuccess(true);
    }
    @ApiOperation(value="分页查询", notes="分页查询")
    @PostMapping(value = "/page")
    public ResponseUtil.Result<PageInfo<MemberInfoDto>> page (@RequestBody SearchPage<SysQueryParam> search){
        PageInfo<MemberInfoDto> page = memberInfoService.page(search);
        return ResponseUtil.addSuccess(page);
    }
    @ApiOperation(value="批量删除", notes="批量删除")
    @DeleteMapping(value="/{id}")
    @Log(title ="删除会员信息" ,businessType = BusinessType.DELETE)
    public ResponseUtil.Result<Boolean> delete(@PathVariable("id") String id){
        memberInfoService.removeIds(Arrays.asList(id.split(",")));
        return ResponseUtil.addSuccess(true);
    }
    @ApiOperation(value="按手机号查询")
    @GetMapping("/getByMobile/{mobile}")
    public ResponseUtil.Result<MemberInfoDto> getByMobile(@PathVariable("mobile") String mobile){
        MemberInfoDto byMobile = memberInfoService.getByMobile(mobile);
        return ResponseUtil.addSuccess(byMobile);
    }
    @ApiOperation(value = "按照会员编号，手机号，年卡编号查询")
    @PostMapping("/indexGetMemberInfo")
    public ResponseUtil.Result<List<CardDto>> indexGetMemberInfo(@RequestBody SearchPage<SysQueryParam> searchPage){
        List<CardDto> memberInfoDtos = memberInfoService.indexGetMemberInfo(searchPage);
        return ResponseUtil.addSuccess(memberInfoDtos);
    }
}
